<?php
declare (strict_types = 1);

namespace app\common\model\Project;

use think\Model;
// 软删除的模型
use think\model\concern\SoftDelete;

/**
 * @mixin \think\Model
 */
class Order extends Model
{

    // 软删除
    use SoftDelete;

    // 预约订单表
    protected $table = 'pre_project_order';

    //开启自动写入时间戳
    protected $autoWriteTimestamp = false; 

    //设置字段的名字
    protected $createTime = false; //插入的时候设置的字段名

    //禁止 写入的时间字段
    protected $updateTime = false;

    // 软删除的字段
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text'
    ];

    public function user()
    {
        return $this->belongsTo(\app\common\model\User\User::class,'userid','id');
    }

    public function project()
    {
        return $this->belongsTo(\app\common\model\Project\Project::class,'projectid','id');
    }

    public function address()
    {
        return $this->belongsTo(\app\common\model\User\Address::class,'addrid','id');
    }

    // 后台状态字段 
    public function getStatusTextAttr($value,$data)
    {
        $StatusList = [0 => '未报价', 1 => '已报价', 2 => '已接单', 3 => '已完成', -1 => '已退单', -2 => '售后中', -3 => '撤销拒绝'];

        return $StatusList[$data['status']];
    }

}
